var e = require("../../../../@babel/runtime/helpers/defineProperty"), t = getApp();

Component({
    properties: {
        show: {
            type: Boolean,
            value: !1
        },
        datas: {
            type: Object,
            value: {}
        },
        cid: {
            type: [ Boolean, String ],
            value: "0"
        },
        scene: {
            type: [ Boolean, String ],
            value: "0"
        },
        order_id: {
            type: [ String ],
            value: "0"
        }
    },
    observers: {
        show: function(e, t) {
            this.setData({
                showControl: e,
                form_data: this.formatterForm()
            });
        }
    },
    data: {
        showControl: !1,
        showDatePicker: !1,
        minDate: new Date(2020, 0, 1).getTime(),
        currentDate: new Date().getTime(),
        currentIndex: 0
    },
    methods: {
        formatterForm: function() {
            var e = this.properties.datas.form_data || [];
            return e.forEach(function(t, a) {
                1 != t.fill_type || 4 != t.form_type && 5 != t.form_type && 6 != t.form_type || (e[a].form_value = "");
            }), e;
        },
        hiddenPop: function() {
            this.setData({
                showControl: !1,
                form_data: []
            });
        },
        handlerInput: function(t) {
            var a = t.target.dataset.index, r = t.target.dataset.type, i = t.detail;
            "number" == r && (i = t.detail.replace(/[^0-9]/gi, "")), "card" == r && (i = t.detail.replace(/[^\d|xX]/g, "")), 
            this.setData(e({}, "form_data[" + a + "].form_value", i));
        },
        toSign: function() {
            var e = !0, a = "";
            if (this.data.form_data.forEach(function(t) {
                1 == t.fill_type && "" == t.form_value && (e = !1, a = "请填写完整数据！"), t.verify && (e = !1, 
                a = "请输入18位身份证号");
            }), !e) return t.tips(a);
            console.log(this.data.form_data), this.toSignPage();
        },
        toSignPage: function() {
            var e = this, a = "", r = {
                scene_id: this.properties.datas.id,
                cid: this.properties.cid,
                form_data: this.data.form_data
            };
            1 == this.properties.scene && (a = "plugin.shop-esign-v2.frontend.controllers.index.order", 
            r.order_id = this.properties.order_id), 2 == this.properties.scene && (a = "plugin.shop-esign-v2.frontend.controllers.index.withdraw"), 
            3 == this.properties.scene && (a = "plugin.shop-esign-v2.frontend.controllers.index.loveChange");
            var i = t.getNetAddresss(a);
            t._postNetWork({
                url: i,
                data: r,
                success: function(t) {
                    var a = t.data;
                    1 === a.result ? (e.hiddenPop(), wx.navigateTo({
                        url: "/packageH/signPage/signPage?id=".concat(a.data.contract_id, "&from=signV2&scene=") + e.properties.scene + "&cid=" + e.properties.cid + "&oid=" + e.properties.order_id || 0
                    })) : wx.showModal({
                        title: "提示",
                        content: a.msg,
                        showCancel: !1
                    });
                },
                fail: function(e) {
                    console.log(e, "----失败-----");
                }
            });
        },
        showDatePickerHandle: function(e) {
            var t = e.target.dataset.index;
            this.setData({
                showDatePicker: !0,
                currentIndex: t
            });
        },
        hiddenDatePickerHandle: function() {
            this.setData({
                showDatePicker: !1
            });
        },
        confirmDatePickerHandle: function(t) {
            var a = t.detail, r = this.timestampToTime(a);
            this.setData(e({
                showDatePicker: !1
            }, "form_data[" + this.data.currentIndex + "].form_value", r));
        },
        timestampToTime: function(e) {
            var t = new Date(e);
            return t.getFullYear() + "-" + ((t.getMonth() + 1 < 10 ? "0" + (t.getMonth() + 1) : t.getMonth() + 1) + "-") + (t.getDate() + 1 < 10 ? "0" + (t.getDate() + 1) : t.getDate() + 1);
        },
        verifyCardLength: function(e) {
            var t = e.currentTarget.dataset.index, a = e.detail;
            this.data.form_data[t].verify = a.length < 18;
        }
    }
});